<?php

namespace App\Http\Controllers\Api;

use App\Http\Requests\DrugRequest;
use App\logic\DrugLogic;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use function Swoole\Coroutine\Http\post;

class DrugController extends BaseController
{
    public function index(){
        try {
            $data = DrugLogic::Index();
            return $this->witejson(0,$data,'列表');
        }catch (\Exception $e){
            return $this->witejson(1,'',$e->getMessage());
        }
    }

    public function read(Request $request){
        try {
            $id = \request()->input();
            $data = DrugLogic::Read($id);
            return $this->witejson(0,$data,'详情');
        }catch (\Exception $e){
//            return $this->witejson(1,'',$e->getMessage());
            return $this->witejson(1,'',$e->validator->errors()->first());
        }
    }

    public function create(){
        try {
            $past = \request()->post();
            DrugLogic::Create($past);
            return $this->witejson(0,'','添加成功');
        }catch (\Exception $e){
            return $this->witejson(1,'',$e->validator->errors()->first());
        }
    }
}
